<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/style.css">
    <style>
        html,body{
            height: 100%;
        }
        body{
            display: flex;
            justify-content: center;
            align-items: center;
            background-image: url("image/login_bg.png");
            background-size: cover;
        }
    </style>
</head>
<body>
<div class="login-div">
    <h1>登录</h1>
    <form id="login-form">
        <div class="login-form-item">
            <input id ='userName' name="username" placeholder="用户名">
        </div>
        <div class="login-form-item">
            <input id ='password' name="password" type="password" placeholder="密码">
        </div>
        <button class="btn-login" type="submit" lay-filter="login">登录</button>
    </form>
</div>
</body>
</html>
<script src="js/jquery.min.js"></script>
<script src="layui/layui.all.js"></script>
<script src="js/common.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
    function mounted(){
       var bossUrl = "https://bckapp.qiwenedu.com.cn";
    // var bossUrl = "http://127.0.0.1:8081";
    $('#login-form').submit(function () {
            var userName = $("#userName").val();
            var password = $("#password").val();
            if(!userName || userName==''){
                layer.msg('请输入用户名');
                return false;
            }
            if(!password || password==''){
                layer.msg('请输入密码');
                return false;
            }
            login(userName,password);
            return false;
        })

        //新增和编辑同一个  试一试  location.href="index.html";
        function login(userName,password) {
            var params ={};
            params["name"] = userName;
            params["password"] = password;
            $.ajax({
                type: 'POST',
                url:bossUrl+ "/user/admin/login",
                dataType: 'json',
                contentType: "application/json;charset=utf-8",
                async: false,
                data:JSON.stringify(params) ,
                success: function (msg) {
                    if(msg.code<0){
                        layer.msg(msg.msg);
                        return false;
                    }
                    console.log(msg)
                    $.cookie('menuView',msg.data.menuView,{ path: "/"});
                    $.cookie('userName',msg.data.name,{ path: "/"});
                    // location.href="index.html"
                    location.href="/static/boss/index.html"
                },
                error: function () {
                    layer.msg("处理失败");
                        return false;
                }
            });
        }
    }

</script>